
package demo.issuetracker.controller;

import demo.issuetracker.model.CustomIdentity;
import demo.issuetracker.entity.Issue;
import demo.issuetracker.entity.User;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.In;


import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
import java.util.Map;
import java.util.List;

/**
 * Glue code to bind Database Debug Service with the view framework (Seam). This class contains
 * a default implementation of the action methods. Please avoid reimplmenting the action methods in this class.
 * The purpose of this class is to declare properties which can be bound to the UI.
 * 
  * This page displays all data stored in the system.
  *
 * Automatically generated by clickframes
 * 
 * @author Vineet Manohar
 */
public abstract class GeneratedDebugController extends Controller {
    @In("#{issueDao}") 
    protected demo.issuetracker.dao.IssueDao issueDao;

    @In("#{issueService}") 
    protected demo.issuetracker.entity.service.IssueService issueService;

    @In("#{userDao}") 
    protected demo.issuetracker.dao.UserDao userDao;

    @In("#{userService}") 
    protected demo.issuetracker.entity.service.UserService userService;



 
    /** the User row which on which the action was performed is stored on 
     * this field via the corresponding action listener if a user performs an action on the 
     * displayed User list 
     */


    /** $!Selected UserList row */
    private User userListSelection;

    /** 
     * Get Selected UserList
     *  
     * @return Selected UserList
     */
    public User getUserListSelection() {
       return this.userListSelection;
    }

    /**
     * Set Selected UserList
     *
     * @param userListSelection
     */
    public void setUserListSelection(User userListSelection) {
        this.userListSelection = userListSelection;
    }


    public void userListListener(ActionEvent actionEvent) {
        UIComponent tmpComponent = actionEvent.getComponent();

        while (null != tmpComponent && !(tmpComponent instanceof UIData)) {
            tmpComponent = tmpComponent.getParent();
        }

        UIData uiData = (UIData) tmpComponent;
        Object selectedRow = uiData.getRowData();
        if (selectedRow instanceof User) {
            this.userListSelection = (User) selectedRow;
        }
    }



    /** $!Display all Users in the system. */
    private List<User> userList;

    /** 
     * Get All Users
     *  
     * @return All Users
     */
    public List<User> getUserList() {
       return this.userList;
    }

    /**
     * Set All Users
     *
     * @param userList
     */
    public void setUserList(List<User> userList) {
        this.userList = userList;
    }


    /** the Issue row which on which the action was performed is stored on 
     * this field via the corresponding action listener if a user performs an action on the 
     * displayed Issue list 
     */


    /** $!Selected IssueList row */
    private Issue issueListSelection;

    /** 
     * Get Selected IssueList
     *  
     * @return Selected IssueList
     */
    public Issue getIssueListSelection() {
       return this.issueListSelection;
    }

    /**
     * Set Selected IssueList
     *
     * @param issueListSelection
     */
    public void setIssueListSelection(Issue issueListSelection) {
        this.issueListSelection = issueListSelection;
    }


    public void issueListListener(ActionEvent actionEvent) {
        UIComponent tmpComponent = actionEvent.getComponent();

        while (null != tmpComponent && !(tmpComponent instanceof UIData)) {
            tmpComponent = tmpComponent.getParent();
        }

        UIData uiData = (UIData) tmpComponent;
        Object selectedRow = uiData.getRowData();
        if (selectedRow instanceof Issue) {
            this.issueListSelection = (Issue) selectedRow;
        }
    }



    /** $!Display all Issues in the system. */
    private List<Issue> issueList;

    /** 
     * Get All Issues
     *  
     * @return All Issues
     */
    public List<Issue> getIssueList() {
       return this.issueList;
    }

    /**
     * Set All Issues
     *
     * @param issueList
     */
    public void setIssueList(List<Issue> issueList) {
        this.issueList = issueList;
    }


    
	@SuppressWarnings("unused")
	private static final Log logger = LogFactory.getLog(GeneratedDebugController.class);

	@In
	protected CustomIdentity identity;

    @Create
    public void init() {


        // initialize all file inputs
          // all inputs initialized here 
    }



    protected void initUserList() {
        // if userList has not been initialized, initialize it now
        if (getUserList() == null) {
            setUserList(loadUserList());
        }
    }

    /**
     * clears the current value and loads the value again
     */
    protected void reloadUserList() {
        clearUserList();
        loadUserList();
    }

    /**
     * clears the current value of All Users 
     */
    protected void clearUserList() {
        setUserList(null);
    }

    protected List<demo.issuetracker.entity.User> loadUserList() {
        return userDao.findUserList(describe());
    }

    protected void initIssueList() {
        // if issueList has not been initialized, initialize it now
        if (getIssueList() == null) {
            setIssueList(loadIssueList());
        }
    }

    /**
     * clears the current value and loads the value again
     */
    protected void reloadIssueList() {
        clearIssueList();
        loadIssueList();
    }

    /**
     * clears the current value of All Issues 
     */
    protected void clearIssueList() {
        setIssueList(null);
    }

    protected List<demo.issuetracker.entity.Issue> loadIssueList() {
        return issueDao.findIssueList(describe());
    }


	/**
	 * This method should be called before the page is loaded
	 * 
	 * All the page parameters should be consumed in this method
	 */    
    public String processPageParameters() {

        initUserList();

        initIssueList();


          // if you need to add more code, override this method in the child class

        return null;
    }





 
 
 





    private static final long serialVersionUID = 1L;

  }// clickframes::version=650760634::clickframes